package com.focus.wecenter.pojo;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.Date;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * @description 回答
 * 
 * @author		Lv Jing
 * @date		2018-1-7 11:32:34
 */
@Entity
@Table(name = "answer", schema = "wecenter")
@DynamicUpdate
@DynamicInsert
public class Answer implements Serializable {
    private static final long serialVersionUID = 1L;

	private Integer id;
	/**回答内容*/
	private String answerContent;
	/**支持人数*/
	private Integer agreeCount;
	/**反对人数*/
	private Integer againstCount;
	/**评论总数*/
	private Integer commentCount;
	/**创建时间*/
	private Date createTime;
    /**所属问题*/
    private Question question;
    /**回答用户*/
    private User user;
    /**该回答已有回复*/
    private Set<AnswerComment> comments = new HashSet<>(0);

    @OneToMany
    @JoinColumn(name = "answer_id")
    @OrderBy("createTime asc")
    public Set<AnswerComment> getComments() {
        return comments;
    }
    public void setComments(Set<AnswerComment> comments) {
        this.comments = comments;
    }
    @JoinColumn(name = "question_id")
    @ManyToOne
    public Question getQuestion() {
        return question;
    }
    public void setQuestion(Question question) {
        this.question = question;
    }
    @JoinColumn(name = "user_id")
    @ManyToOne
    public User getUser() {
        return user;
    }
    public void setUser(User user) {
        this.user = user;
    }
    @Id
    @Column(name = "ANSWER_ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@Basic
    @Lob
    @Type(type = "text")
    @Column(name = "ANSWER_CONTENT")
	public String getAnswerContent() {
		return this.answerContent;
	}
	public void setAnswerContent(String answerContent) {
		this.answerContent = answerContent;
	}	
	@Basic
    @Column(name = "AGREE_COUNT")
	public Integer getAgreeCount() {
		return this.agreeCount;
	}
	public void setAgreeCount(Integer agreeCount) {
		this.agreeCount = agreeCount;
	}	
	@Basic
    @Column(name = "AGAINST_COUNT")
	public Integer getAgainstCount() {
		return this.againstCount;
	}
	public void setAgainstCount(Integer againstCount) {
		this.againstCount = againstCount;
	}	
	@Basic
    @Column(name = "COMMENT_COUNT")
	public Integer getCommentCount() {
		return this.commentCount;
	}
	public void setCommentCount(Integer commentCount) {
		this.commentCount = commentCount;
	}	
	@Basic
    @Column(name = "CREATE_TIME")
	public Date getCreateTime() {
		return this.createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Answer answer = (Answer) o;
        return Objects.equals(id, answer.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}